/*
Adding (blending) two images using OpenCV
Simple linear blender ( dst = alpha*src1 + beta*src2 )

- Access pixel values
- Initialize a matrix with zeros
- Learn what cv::saturate_cast does and why it is useful
- Get some cool info about pixel transformations

http://docs.opencv.org/3.2.0/d3/dc1/tutorial_basic_linear_transform.html
Data:2017.04.24
*/

#include <opencv2/opencv.hpp>
#include <iostream>
using namespace cv;
double alpha; /*< Simple contrast control */
int beta;  /*< Simple brightness control */
int main( int argc, char** argv )
{
    Mat image = imread( "../data/image.jpg" );
    Mat new_image = Mat::zeros( image.size(), image.type() );
    std::cout<<" Basic Linear Transforms "<<std::endl;
    std::cout<<"-------------------------"<<std::endl;
//    std::cout<<"* Enter the alpha value [1.0-3.0]: ";std::cin>>alpha;
//    std::cout<<"* Enter the beta value [0-100]: "; std::cin>>beta;
    alpha = 1;
    beta = 100;

    for( int y = 0; y < image.rows; y++ ) {
        for( int x = 0; x < image.cols; x++ ) {
            for( int c = 0; c < 3; c++ ) {
                new_image.at<Vec3b>(y,x)[c] =
                saturate_cast<uchar>( alpha*( image.at<Vec3b>(y,x)[c] ) + beta );
            }
        }
    }
    namedWindow("Original Image", 1);
    namedWindow("New Image", 1);
    imshow("Original Image", image);
    imshow("New Image", new_image);
    waitKey();
    return 0;
}
